package com.mesSystem.controller;

import cn.hutool.db.sql.Order;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mesSystem.dto.Result;
import com.mesSystem.entity.OrderBom;
import com.mesSystem.entity.ProductionWorkstation;
import com.mesSystem.service.impl.OrderBomService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@ResponseBody
@RequestMapping("orderBom")
public class OrderBomController {
    @Autowired
    OrderBomService orderBomService;

    /**
     * 创建 order-bom单
     * 提示：查询仓库物料请访问WmsSystem的物料明细查找功能（为什么那么麻烦？因为懒人无奈堆了屎山）
     * @param orderBom
     * @return
     */
    @PostMapping("increase")
    public Result increase(@RequestBody OrderBom orderBom) {
        log.info(orderBom.toString());
        orderBomService.save(orderBom);
        return Result.ok("创建成功");
    }


    /**
     * 删除工位安排信息
     * TODO---根据订单删除相关内容
     *
     * @param
     * @return
     */
    @DeleteMapping("delete")
    public Result delete(Long orderBomId) {
        orderBomService.removeById(orderBomId);
        return Result.ok("删除成功");
    }


    /**
     * 根据已经分配的工位的工位id，查找该工位使用的物料
     * @param productionWorkstationId
     * @return
     */
    @GetMapping("queryBom")
    public Result query(Long productionWorkstationId) {
        QueryWrapper<OrderBom> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("production_workstation_id", productionWorkstationId);
        List<OrderBom> list = orderBomService.list(queryWrapper);
        // 返回分页结果
        return Result.ok(list);
    }


    /**
     * 更改
     */
    @PostMapping("update")
    public Result update(@RequestBody OrderBom orderBom) {
        orderBomService.updateById(orderBom);
        return Result.ok("更新成功");
    }
}
